//
// A very simple generic main.c that uses Luminary Driverlib
// 
// (c) Code Red Technologies 2008-10
// 
// 

#include "hw_memmap.h"
#include "hw_types.h"
#include "sysctl.h"
#include "hw_sysctl.h"
#include "rit128x96x4.h"
#include "MR102A.h"
#include "FineLocalization.h"
#include <stdio.h>
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
// If Driverlib has been built with the symbol 'DEBUG' defined then this is 
// needed.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif


const unsigned char g_pucAccessKey[] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
unsigned char pucUID[6], ucAddr;
unsigned long ulUIDSize, ulValue;
unsigned int iResult;

int main(void)
{
    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(DEVICE_IS_REVA2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

       
    //
    // Set the clocking to run directly from the crystal.
    //
	// Default values assume an external crystal of 6MHz. See Luminary
	// driverlib documentation for other values.
	//
	// Clock source can be: 
	//		'SYSCTL_USE_OSC | SYSCTL_OSC_MAIN' - use the xtal without PLL
	//		'SYSCTL_USE_PLL | SYSCTL_OSC_MAIN' - use the xtal with PLL
	//
	//
	// If using the PLL, the oscillator runs at 200MHz and then you select a division of this
	// frequency to clock the core. Otherwise the divider just directly divides the XTAL
    // frequency.
	//
    //
	
	// Use a 6MHz external XTAL directly with no division
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
	
	// Use the XTAL directly to clock the PLL with division by 4
    // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
    
    // *** INSERT OTHER INITIALIZATION CODE HERE ***

    RIT128x96x4Init(1000000);		// initialize Oled display
    // *** INSERT APPLICATION CODE HERE ***
    MR102AInit();						// initialize rfid stuff
    //resetMR102A();					// only if you change settings or somethings wrong
    fineLocalize(0,0,-70,-20,20,70);
    printf("x: %f y:%f phi: %f\n",getXCar(),getYCar(),getPhiCar());
    while(1)
    {
    	tagEventChecker();
    }
    // An embedded application should never get here!
    while(1);
}










